package com.azdebugit.trancation.test.pojo;

import com.azdebugit.trancation.test.util.JsonUtil;
import lombok.Data;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.reflect.MethodSignature;

import java.lang.reflect.Method;

//辅助类
@Data
public class MethodInfo {
    /*** 切入点信息*/
    private JoinPoint joinPoint;
    /*** 方法签名*/
    private MethodSignature signature;
    /*** 方法信息*/
    private Method method;
    /*** 类信息*/
    private Class<?> targetClass;
    /*** 参数信息*/
    private Object[] args;
    /*** 参数信息String*/
    private String jsonArgs;
    /*** 类名*/
    private String className;
    /*** 方法名*/
    private String methodName;

    public MethodInfo(JoinPoint joinPoint) {
        this.joinPoint = joinPoint;
    }

    public void init() {
        this.signature = (MethodSignature) joinPoint.getSignature();
        this.method = signature.getMethod();
        this.methodName = method.getName();
        this.targetClass = method.getDeclaringClass();
        this.className = targetClass.getName();
        this.args = joinPoint.getArgs();
        if (args.length == 1) {
            this.jsonArgs = JsonUtil.toJsonString(args[0]);
        } else {
            this.jsonArgs = JsonUtil.toJsonString(args);
        }

    }

}